home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / adaptsca.c < prev    next >
Text File  |  1994-01-03  |  10KB  |  401 lines

  1. # include "Scalar.h"
  2. # include "yyAScala.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 8 "AdaptScalar.puma"
  36.  
  37. # include <stdio.h>
  38. # include "Idents.h"
  39. # include "StringMe.h"
  40.  
  41. # include "protocol.h"
  42.  
  43. # include "Types.h"         /* LastIndex       */
  44. # include "Transfor.h"     /* ExpToVarParam   */
  45. # include "Dalib.h"         /* IsHost, ...     */
  46. # include "Movement.h"   /* AdaptNNCopy */
  47. # include "Reductio.h"
  48. # include "Local.h"      /* LocalArrayAssignment */
  49. # include "Broadcas.h"  /* MakeBroadcast */
  50.  
  51.  
  52.  
  53. static FILE * yyf = stdout;
  54.  
  55. static void yyAbort
  56. # ifdef __cplusplus
  57.  (char * yyFunction)
  58. # else
  59.  (yyFunction) char * yyFunction;
  60. # endif
  61. {
  62.  (void) fprintf (stderr, "Error: module AdaptScalar, routine %s failed\n", yyFunction);
  63.  exit (1);
  64. }
  65.  
  66. tTree AdaptScalarAssign ARGS((tTree assign, int vardistribution, int expdistribution));
  67. static tTree AdaptScalarReduction ARGS((tTree assign, tTree var, tTree exp));
  68. static tTree GenReductionStmt ARGS((tTree var, tTree funccall));
  69.  
  70. tTree AdaptScalarAssign
  71. # if defined __STDC__ | defined __cplusplus
  72. (register tTree assign, register int vardistribution, register int expdistribution)
  73. # else
  74. (assign, vardistribution, expdistribution)
  75.  register tTree assign;
  76.  register int vardistribution;
  77.  register int expdistribution;
  78. # endif
  79. {
  80. # line 34 "AdaptScalar.puma"
  81.  
  82. tTree mask, t;
  83. char string[200];
  84.  
  85.   if (assign->Kind == kACF_BASIC) {
  86.   if (assign->ACF_BASIC.BASIC_STMT->Kind == kASSIGN_STMT) {
  87.   if (equalint (vardistribution, 0)) {
  88.   if (equalint (expdistribution, 0)) {
  89. # line 45 "AdaptScalar.puma"
  90.    return assign;
  91.  
  92.   }
  93.   }
  94.   if (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->Kind == kVAR_EXP) {
  95.   if (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V->Kind == kINDEXED_VAR) {
  96.  {
  97.   tTree new;
  98.   if (equalint (vardistribution, 0)) {
  99.   if (equalint (expdistribution, - 1)) {
  100. # line 58 "AdaptScalar.puma"
  101.   {
  102. # line 61 "AdaptScalar.puma"
  103.  
  104. # line 63 "AdaptScalar.puma"
  105.   if (IsHost)
  106.        { new = MakeBroadcast (CopyTree (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR));
  107.          new = mACF_LIST (assign, mACF_LIST (new, NoTree));
  108.        }
  109.        else
  110.         new = MakeBroadcast (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR);
  111.  
  112.   }
  113.   {
  114.    return new;
  115.   }
  116.  
  117.   }
  118.   }
  119.  }
  120.  {
  121.   tTree params;
  122.   tTree new;
  123.   if (equalint (vardistribution, 0)) {
  124.   if (equalint (expdistribution, 1)) {
  125. # line 82 "AdaptScalar.puma"
  126.   {
  127. # line 89 "AdaptScalar.puma"
  128.  
  129. # line 90 "AdaptScalar.puma"
  130.  
  131. # line 92 "AdaptScalar.puma"
  132.  params = DalibLastActualParam (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V, mBTP_EMPTY());
  133.      params = DalibLastFormalParam (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V, params);
  134.      params = DalibTreeSizeParam   (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V, params);
  135.      if (IsHost)
  136.         params = mBTP_LIST (mVAR_PARAM (CopyTree(assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR)), params);
  137.       else
  138.         params = mBTP_LIST (mVAR_PARAM (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V), params);
  139.  
  140.      params = mBTP_LIST (mVAR_PARAM (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR), params);
  141.  
  142.      new = mCALL_STMT (mPROC_OBJ (MakeDalibId ("node_get")), params);
  143.      new = mACF_BASIC (new);
  144.  
  145.   }
  146.   {
  147.    return new;
  148.   }
  149.  
  150.   }
  151.   }
  152.  }
  153.   }
  154.   }
  155.   if (equalint (vardistribution, 0)) {
  156. # line 115 "AdaptScalar.puma"
  157.   {
  158. # line 116 "AdaptScalar.puma"
  159.    if (! ((IsReduction (assign) == true))) goto yyL4;
  160.   {
  161. # line 117 "AdaptScalar.puma"
  162.  t = AdaptScalarReduction (assign, assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR, assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP);
  163.      if (t == NoTree)
  164.         error_protocol ("adaption of reduction fails\n");
  165.  
  166.   }
  167.   }
  168.    return t;
  169. yyL4:;
  170.  
  171.   }
  172.   if (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR->Kind == kINDEXED_VAR) {
  173.   if (equalint (vardistribution, 1)) {
  174.   if (equalint (expdistribution, 0)) {
  175. # line 130 "AdaptScalar.puma"
  176.   {
  177. # line 134 "AdaptScalar.puma"
  178.   if (IsHost)
  179.          t = NoTree;
  180.         else
  181.          t = LocalArrayAssignment (assign);
  182.  
  183.  
  184.   }
  185.    return t;
  186.  
  187.   }
  188.   }
  189.   if (equalint (vardistribution, 1)) {
  190.   if (equalint (expdistribution, 1)) {
  191. # line 149 "AdaptScalar.puma"
  192.   {
  193. # line 150 "AdaptScalar.puma"
  194.  if (!IsHost)
  195.        { if (CountMovements (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR, assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP) == 0)
  196.             {
  197.               t = LocalArrayAssignment (assign);
  198.             }
  199.           else if (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->Kind != kVAR_EXP)
  200.             { error_protocol ("Scalar Node-Copy failed");
  201.               t = NoTree;
  202.             }
  203.           else
  204.             {
  205.               stmt_protocol ("Scalar Node<->Node Transfer");
  206.               t = AdaptNNCopy (assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_VAR, assign->ACF_BASIC.BASIC_STMT->ASSIGN_STMT.ASSIGN_EXP->VAR_EXP.V);
  207.               if (t == NoTree)
  208.                  error_protocol ("fails");
  209.                 else
  210.                  tree_protocol ("becomes : ", t);
  211.             }
  212.        }
  213.       else t = NoTree;
  214.  
  215.   }
  216.    return t;
  217.  
  218.   }
  219.   }
  220.   if (equalint (vardistribution, - 1)) {
  221.   if (equalint (expdistribution, 0)) {
  222. # line 179 "AdaptScalar.puma"
  223.   {
  224. # line 183 "AdaptScalar.puma"
  225.  if (IsHost)
  226.           mask = assign;
  227.        else
  228.           mask = NoTree;
  229.  
  230.   }
  231.    return mask;
  232.  
  233.   }
  234.   }
  235.   if (equalint (vardistribution, - 1)) {
  236.   if (equalint (expdistribution, - 1)) {
  237. # line 191 "AdaptScalar.puma"
  238.   {
  239. # line 195 "AdaptScalar.puma"
  240.  if (IsHost)
  241.           mask = assign;
  242.        else
  243.           mask = NoTree;
  244.  
  245.   }
  246.    return mask;
  247.  
  248.   }
  249.   }
  250.   }
  251.   }
  252.   }
  253.   if (equalint (vardistribution, - 1)) {
  254. # line 203 "AdaptScalar.puma"
  255.   {
  256. # line 204 "AdaptScalar.puma"
  257.    error_protocol ("Update of a host var with distributed var");
  258.   }
  259.    return assign;
  260.  
  261.   }
  262. # line 208 "AdaptScalar.puma"
  263.   {
  264. # line 209 "AdaptScalar.puma"
  265.    sprintf (string, "AdaptScalarAssign failed, vardist= %d, expdist= %d\n", vardistribution, expdistribution);
  266. # line 211 "AdaptScalar.puma"
  267.    error_protocol (string);
  268.   }
  269.    return assign;
  270.  
  271. }
  272.  
  273. static tTree AdaptScalarReduction
  274. # if defined __STDC__ | defined __cplusplus
  275. (register tTree assign, register tTree var, register tTree exp)
  276. # else
  277. (assign, var, exp)
  278.  register tTree assign;
  279.  register tTree var;
  280.  register tTree exp;
  281. # endif
  282. {
  283. # line 224 "AdaptScalar.puma"
  284.  
  285. tTree mask, t, last;
  286.  
  287.   if (exp->Kind == kFUNC_CALL_EXP) {
  288.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->Kind == kBTP_LIST) {
  289.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->Kind == kVAR_PARAM) {
  290.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->Kind == kUSED_VAR) {
  291. # line 228 "AdaptScalar.puma"
  292.   {
  293. # line 230 "AdaptScalar.puma"
  294.  
  295.       t = GenReductionStmt (var, exp);
  296.       if (t == NoTree)
  297.         { error_protocol ("generate reduction fails");
  298.           t = assign;
  299.         }
  300.        else
  301.         { stmt_protocol ("Global reduction: ");
  302.           if (!IsHost)
  303.             t = mACF_LIST (assign, mACF_LIST (t, NoTree));
  304.         }
  305.  
  306.   }
  307.    return t;
  308.  
  309.   }
  310.   if (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->Kind == kINDEXED_VAR) {
  311. # line 245 "AdaptScalar.puma"
  312.   {
  313. # line 247 "AdaptScalar.puma"
  314.  
  315.       t = GenReductionStmt (var, exp);
  316.       if (!IsHost)
  317.         {
  318.           t = mACF_LIST (assign, mACF_LIST (t, NoTree));
  319.           last = LastIndex (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_EXPS);
  320.           if (last->Kind == kSLICE_EXP)
  321.              {
  322.                mask = MakeRangeStmt (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_VAR, last);
  323.  
  324.                if (mask != NoTree)
  325.                   t = mACF_LIST (mask, t);
  326.              }
  327.             else
  328.              {
  329.                mask = MakeRangeStmt (exp->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Elem->VAR_PARAM.V->INDEXED_VAR.IND_VAR, last);
  330.  
  331.                if (mask != NoTree)
  332.                   t = mACF_LIST (mask, t);
  333.              }
  334.         }
  335.  
  336.   }
  337.    return t;
  338.  
  339.   }
  340.   }
  341.   }
  342.   }
  343. # line 272 "AdaptScalar.puma"
  344.    return NoTree;
  345.  
  346. }
  347.  
  348. static tTree GenReductionStmt
  349. # if defined __STDC__ | defined __cplusplus
  350. (register tTree var, register tTree funccall)
  351. # else
  352. (var, funccall)
  353.  register tTree var;
  354.  register tTree funccall;
  355. # endif
  356. {
  357. # line 279 "AdaptScalar.puma"
  358.  tTree t;
  359.   if (funccall->Kind == kFUNC_CALL_EXP) {
  360.   if (funccall->FUNC_CALL_EXP.FUNC_PARAMS->Kind == kBTP_LIST) {
  361.   if (funccall->FUNC_CALL_EXP.FUNC_PARAMS->BTP_LIST.Next->Kind == kBTP_EMPTY) {
  362. # line 281 "AdaptScalar.puma"
  363.   {
  364. # line 282 "AdaptScalar.puma"
  365.  t = GlobalReductionStmt (var, TreeType (var), funccall->FUNC_CALL_EXP.FUNC_ID);
  366.   }
  367.    return t;
  368.  
  369.   }
  370.   }
  371. # line 287 "AdaptScalar.puma"
  372.   {
  373. # line 288 "AdaptScalar.puma"
  374.    printf ("Generate Reduction Statement failed (too many params)\n");
  375. # line 289 "AdaptScalar.puma"
  376.    printf ("var = ");
  377. # line 289 "AdaptScalar.puma"
  378.    FileUnparse (stdout, var);
  379. # line 289 "AdaptScalar.puma"
  380.    printf ("\n");
  381. # line 290 "AdaptScalar.puma"
  382.    printf ("call = ");
  383. # line 290 "AdaptScalar.puma"
  384.    FileUnparse (stdout, funccall);
  385. # line 290 "AdaptScalar.puma"
  386.    printf ("\n");
  387.   }
  388.    return NoTree;
  389.  
  390.   }
  391.  yyAbort ("GenReductionStmt");
  392. }
  393.  
  394. void BeginAdaptScalar ()
  395. {
  396. }
  397.  
  398. void CloseAdaptScalar ()
  399. {
  400. }
  401.